package net.jalbum.filters;

import java.awt.event.ActionEvent;

import javax.swing.JLabel;
import javax.swing.JSlider;

import se.datadosen.jalbum.Msg;
import net.jalbum.filters.components.ExtendedSlider;


public class BlurControl extends FilterControl {
	/**
	 *
	 */
	private static final long serialVersionUID = -7969686269619548580L;
	protected BlurFilterPlugin blurFilterPlugin;

    protected ExtendedSlider strengthSlider;
	protected JLabel textStrength;

	public BlurControl(){}

	public BlurControl(BlurFilterPlugin blurFilterPlugin) {

		init(blurFilterPlugin);

		addBlurControls();

	}

	protected void addBlurControls() {
		textStrength = new JLabel(Msg.getString(this,"filters.blur.strength"));
		strengthSlider = new ExtendedSlider(JSlider.HORIZONTAL,0,100,blurFilterPlugin.getStrength());
		strengthSlider.getSlider().setMajorTickSpacing(25);
		strengthSlider.getSlider().setMinorTickSpacing(5);
		strengthSlider.getSlider().setSnapToTicks(false);
		strengthSlider.getSlider().setPaintLabels(false);
		strengthSlider.setSliderWidth(SLIDER_WIDTH);
		strengthSlider.removeResetButton();
		strengthSlider.addActionListener(this);

		this.add(textStrength);
		this.add("br",strengthSlider);
    }

	protected void init(BlurFilterPlugin blurFilterPlugin) {
		this.blurFilterPlugin = blurFilterPlugin;

		super.init(blurFilterPlugin);
	}

    @Override
	public void actionPerformed(ActionEvent e) {
		super.actionPerformed(e);

		if (e.getSource()== strengthSlider){
			if(strengthSlider.getValue()!=blurFilterPlugin.getStrength()){
				blurFilterPlugin.adjustStrength(strengthSlider.getValue());
			}
		}
	}
}
